
class SessionHandler(object):
    def __init__(self, connection, write_handler):
        self. __connection = connection

    def on_error(self, error_code):
        raise NotImplementedError()

    def on_connected(self):
        raise NotImplementedError()
    def on_disconnected(self, reason):
        raise NotImplementedError()

    def on_read(self, nbytes, msg_type):
        raise NotImplementedError()

    def __str__(self):
        return "Handler"

class SessionNameSeq(object):
    def __init__(self):
        self.__seq = 0

    def get(self):
       self.__seq += 1 
       return "ses_{}".format(self.__seq)

    def clear(self):
        self.__seq = 0

class Session(object):

    SESSION_NAME_SEQ = SessionNameSeq()

    def __init__(self, service, handler, **kwargs):
        self.__service = service if service is not None else None
        self.__handler = handler if handler is not None else None

        name = kwargs.get("name")
        self.__name = name if name is not None else Session.SESSION_NAME_SEQ.get()

        ip=kwargs.get("ip")
        self.__ip = ip if ip is not None else "127.0.0.1"

        port=kwargs.get("port")
        self.__port = port if port is not None and port > 0 else 3467

        heartbeat_timeout=kwargs.get("heartbeat_timeout")
        self.__heartbeat_timeout = heartbeat_timeout if heartbeat_timeout is not None and heartbeat_timeout > 0 else 60 # for recv heatbeat

        heatbeat_send_interval = kwargs.get("heatbeat_send_interval")
        self.__heatbeat_send_interval = heatbeat_send_interval if heatbeat_send_interval is not None and heatbeat_send_interval > 0 else 20

        connect_timeout = kwargs.get("connect_time_ms")
        self.__connect_timeout = connect_timeout if connect_timeout is not None else 2000


    #@override
    def is_connected(self):
        raise NotImplementedError()

    #@override
    def connect(self): # -> on_connected
        raise NotImplementedError()

    #@override
    def disconnect(self): #-> on_disconnected
        raise NotImplementedError()

    #@override
    def write(self, msg):
        raise NotImplementedError()

    def write_encrypt(self, msg):
        raise NotImplementedError()
        

    def name(self):
        return self.__name
    def set_name(self, value):
        self.__name = value
        return self

    #@override
    def ip(self):
        return self.__ip
    def set_ip(self, value):
        self.__ip = value
        return self

    #@override
    def port(self):
        return self.__port

    def set_port(self, value):
        self.port = value
        return self

    def handler(self):
        return self.__handler
    def set_handler(self, value):
        self.__handler = value
        return self

    #@override
    def heartbeat_timeout(self):
        return self.__heartbeat_timeout
    #@override
    def set_heartbeat_timeout(self, value):
        self.__heartbeat_timeout = value 
        return self

    def __str__(self):
        return "Session: name:{},ip:{},port:{},handler:{},service:{}".format(
            self.__name,
            self.__ip,
            self.__port,
            self.__handler,
            self.__service,
        )
    def service(self):
        return self.__service




import unittest
class TestSession(unittest.TestCase):
    def test_main(self):
        pass
    def test_name_seq(self):
        pass
    def test_session_handler(self):
        pass

if __name__ == '__main__':
    unittest.main() 
